package cn.zaier.javafx.controlle;

import cn.hutool.extra.spring.SpringUtil;
import javafx.concurrent.ScheduledService;
import javafx.concurrent.Task;

import java.util.List;
import java.util.Map;

public class ClearScheduledService extends ScheduledService {

    private  final   String fileDir; // 扫描文件目录
    private final  String fileTypes; // 文件类型
    private final  long longtime; //  执行间隔
    private final  Map<String,Object> extArgs;// 扩展其它参数

    private  final InitSceneViewControlle initSceneViewControlle;



    public ClearScheduledService(String fileDir, String fileTypes, long longtime,Map<String,Object> extArgs) {
        this.fileDir = fileDir;
        this.fileTypes = fileTypes;
        this.longtime = longtime;
        this.extArgs= extArgs;
        this.initSceneViewControlle = SpringUtil.getBean(InitSceneViewControlle.class);
    }

    @Override
    public void start() {
        initSceneViewControlle.printLog("定时任务","开始执行");
        super.start();
    }

    @Override
    protected Task createTask() {
        FileClearWork fileClearWork = new FileClearWork(fileDir, fileTypes, longtime, extArgs);
        List<String> call = fileClearWork.call();
        for (String s : call) {
            System.out.println("删除文件路径: "+s);
            initSceneViewControlle.printLog("删除文件路径",s);
        }
        return fileClearWork;
    }
}
